package com.hewep.demo.device.mina.core.codec;

import com.hewep.demo.device.mina.core.Response;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

public class DeviceEncoder implements ProtocolEncoder {
	@Override
	public void dispose(IoSession session) throws Exception {


	}

	@Override
	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
		if(message instanceof Response){
			Response response = (Response)message;
			response = (Response)message;
			out.write(IoBuffer.wrap(response.getData()));
		}else if(message instanceof byte[]){
			out.write(IoBuffer.wrap((byte[])message));
		}else{
			out.write(message);
		}
		
	}
	
}
